package com.zha.controller;

import com.zha.domain.SysMenu;
import com.zha.model.Result;
import com.zha.service.SysMenuService;
import com.zha.util.AuthUtils;
import com.zha.vo.MenuAndAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @Title: 只有光头才能变强
 * @Author: 炸炸
 * @Date: 2024/12/14 17:03
 * 系统权限控制层
 */
@Api(tags = "系统权限接口管理")
@RequestMapping("sys/menu")
@RestController  // 相当于@Controller + 和方法上添加的注解@ResponseBody,即该控制层下的所有方法都以json格式返回数据
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;


    @ApiOperation(value = "查询用户菜单权限和操作权限")
    @GetMapping(value = "nav")
    public Result<MenuAndAuth> loadSysMenuAndAuth(){
        // 获取登录用户的标识
        Long userId = AuthUtils.geiLoginSysUserId();
        // 根据用户标识查询菜单权限集合
        Set<SysMenu> menus = sysMenuService.querySysUserListById(userId);
        // 从security容器中获取用户的操作权限集合
        Set<String> perms = AuthUtils.getLoginSysUserPerms();

        // 封装对象
        MenuAndAuth menuAndAuth = new MenuAndAuth(menus, perms);

        return Result.success(menuAndAuth);
    }
}
